package com.lanjiu.lib.imclient.ims.read;

import android.text.TextUtils;

import com.lanjiu.lib.imclient.dto.GroupVo;
import com.lanjiu.lib.imclient.dto.VersionDto;
import com.lanjiu.lib.imclient.ims.IMSRequester;
import com.lanjiu.lib.imclient.ims.IMSUtils;
import com.lanjiu.lib.imclient.ims.offline.IMSOfflineMessageHandler;
import com.lanjiu.lib.utils.sp.SPKeys;
import com.lanjiu.lib.utils.sp.SharedPreferenceHelper;
import com.lanjiu.lib.utils.th.Threader;
import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.pro.business.BusinessProtocolMessageStandard;
import com.lanjiu.pro.business.BusinessProtocolMessages;
import com.lanjiu.lib.app.App;
import com.lanjiu.lib.imclient.bus.EventConstants;
import com.lanjiu.lib.imclient.bus.MessageEvent;
import com.lanjiu.lib.imclient.dto.FriendDto;
import com.lanjiu.lib.imclient.dto.GroupDto;
import com.lanjiu.lib.imclient.dto.GroupMemberDto;
import com.lanjiu.lib.imclient.dto.OffMsgDto;
import com.lanjiu.lib.imclient.dto.user.RegisteredUserDto;
import com.lanjiu.lib.imclient.dto.SettingsDto;
import com.lanjiu.lib.imclient.dto.user.TouristsUserDto;
import com.lanjiu.lib.imclient.dto.chat.ChatMessageDto;
import com.lanjiu.lib.imclient.dto.extra.ChatFriendMsgDto;
import com.lanjiu.lib.imclient.dto.extra.ChatGroupMsgDto;
import com.lanjiu.lib.imclient.dto.extra.GroupInfoDto;
import com.lanjiu.lib.imclient.dto.extra.NotifyListDto;
import com.lanjiu.lib.imclient.dto.extra.SearchResultDto;
import com.lanjiu.lib.imclient.dto.notify.NotifyDto;
import com.lanjiu.lib.imclient.dto.notify.SysNotifyDto;
import com.lanjiu.lib.imclient.ims.IMSContacts;
import com.lanjiu.lib.imclient.user.UserPreferences;
import com.lanjiu.lib.utils.CollectionUtils;
import com.lanjiu.lib.utils.file.FileOperator;
import com.lanjiu.lib.utils.json.JsonUtils;
import com.lanjiu.lib.utils.log.Logger;
import com.ljkj.cordial.chat.R;
import com.ljkj.cordial.chat.base.ChatApp;
import com.ljkj.cordial.chat.bean.Canstants;
import com.ljkj.cordial.chat.bean.MsgType;
import com.ljkj.cordial.chat.dao.AlbumTableBean;
import com.ljkj.cordial.chat.dao.ChatTableBean;
import com.ljkj.cordial.chat.dao.DbController;
import com.ljkj.cordial.chat.dao.notify.ChatContentTable;
import com.ljkj.cordial.chat.dao.notify.GroupMemberTable;
import com.ljkj.cordial.chat.dao.notify.GroupTable;
import com.ljkj.cordial.chat.util.AlbumManageUtil;
import com.yanzhenjie.album.util.AlbumUtils;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: Panwei
 * @date: 2019/11/7 20:48
 */
public class IMSMessageReader {

    public MessageEvent getRead(int code, String msgType, BusinessProtocolMessageStandard.UnifiedEntranceMessage message, String error) {
        return getMessageEvent(code, msgType, message, error);
    }

    private boolean isError(int responseCode, String error) {
        return responseCode != IMSContacts.ResponseCode.SUCCESS && !TextUtils.isEmpty(error);
    }

    private MessageEvent getMessageEvent(int responseCode, String msgType, BusinessProtocolMessageStandard.UnifiedEntranceMessage message, String error) {
        if (message == null) return null;
        BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType dataType = message.getDataType();
        MessageEvent event = null;
        switch (msgType) {
            case IMSContacts.MsgType.REGISTER:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.RegisteredUserProtocol == dataType) {
                    BusinessProtocolMessages.RegisteredUserProtocol registeredUserProtocol = message.getRegisteredUserProtocol();
                    if (null == registeredUserProtocol) return null;
                    event = onRegisterResponseReader(responseCode, isError(responseCode, error) ? error : registeredUserProtocol.getStatusDetail(), registeredUserProtocol.getRegisteredUser());
                }
                break;
            case IMSContacts.MsgType.LOGIN_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.LoginProtocol == dataType) {
                    BusinessProtocolMessages.LoginProtocol loginProtocol = message.getLoginProtocol();
                    if (null == loginProtocol) return null;
                    event = onLoginAsTouristsReader(responseCode, isError(responseCode, error) ? error : loginProtocol.getStatusDetail(), loginProtocol.getTouristsUser());
                }
                break;
            case IMSContacts.MsgType.LOGIN_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.LoginProtocol == dataType) {
                    BusinessProtocolMessages.LoginProtocol loginProtocol = message.getLoginProtocol();
                    if (null == loginProtocol) return null;
                    event = onLoginAsRegisteredReader(responseCode, isError(responseCode, error) ? error : loginProtocol.getStatusDetail(), loginProtocol.getRegisteredUser());
                }
                break;
            case IMSContacts.MsgType.LOGOUT_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.LogoutProtocol == dataType) {
                    BusinessProtocolMessages.LogoutProtocol logoutProtocol = message.getLogoutProtocol();
                    if (null == logoutProtocol) return null;
                    event = onLogoutAsTouristsReader(responseCode, isError(responseCode, error) ? error : logoutProtocol.getStatusDetail(), logoutProtocol.getTouristsUser());
                }
                break;
            case IMSContacts.MsgType.LOGOUT_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.LogoutProtocol == dataType) {
                    BusinessProtocolMessages.LogoutProtocol logoutProtocol = message.getLogoutProtocol();
                    if (null == logoutProtocol) return null;
                    event = onLogoutAsRegisteredReader(responseCode, isError(responseCode, error) ? error : logoutProtocol.getStatusDetail(), logoutProtocol.getRegisteredUser());
                }
                break;
            case IMSContacts.MsgType.FRIEND_FIND_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FindUserProtocol == dataType) {
                    BusinessProtocolMessages.FindUserProtocol findUserProtocol = message.getFindUserProtocol();
                    if (null == findUserProtocol) return null;
                    event = onFriendFindAsTouristsReader(responseCode, isError(responseCode, error) ? error : findUserProtocol.getStatusDetail(), findUserProtocol.getRegisteredFindList(), findUserProtocol.getTouristsFindList());
                }
                break;
            case IMSContacts.MsgType.FRIEND_FIND_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FindUserProtocol == dataType) {
                    BusinessProtocolMessages.FindUserProtocol findUserProtocol = message.getFindUserProtocol();
                    if (null == findUserProtocol) return null;
                    event = onFriendFindAsRegisteredReader(responseCode, isError(responseCode, error) ? error : findUserProtocol.getStatusDetail(), findUserProtocol.getRegisteredFindList(), findUserProtocol.getTouristsFindList());
                }
                break;
            case IMSContacts.MsgType.FRIEND_LIST_TOURISTS:
            case IMSContacts.MsgType.FRIEND_LIST_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendListProtocol == dataType) {
                    BusinessProtocolMessages.FriendListProtocol friendListProtocol = message.getFriendListProtocol();
                    if (null == friendListProtocol) return null;
                    event = onFriendListReader(responseCode, isError(responseCode, error) ? error : friendListProtocol.getStatusDetail(), friendListProtocol.getRegisteredFriendList(), friendListProtocol.getTouristsFriendList());
                }
                break;
            case IMSContacts.MsgType.FRIEND_INFO_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendInfoProtocol == dataType) {
                    BusinessProtocolMessages.FriendInfoProtocol friendInfoProtocol = message.getFriendInfoProtocol();
                    if (null == friendInfoProtocol) return null;
                    event = onFriendInfoAsTouristsReader(responseCode, isError(responseCode, error) ? error : friendInfoProtocol.getStatusDetail(), friendInfoProtocol.getTouristsFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_INFO_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendInfoProtocol == dataType) {
                    BusinessProtocolMessages.FriendInfoProtocol friendInfoProtocol = message.getFriendInfoProtocol();
                    if (null == friendInfoProtocol) return null;
                    event = onFriendInfoAsRegisteredReader(responseCode, isError(responseCode, error) ? error : friendInfoProtocol.getStatusDetail(), friendInfoProtocol.getRegisteredFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_ONLINE_STATUS_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendOnlineStatusChangeProtocol == dataType) {
                    BusinessProtocolMessages.FriendOnlineStatusChangeProtocol friendOnlineStatusChangeProtocol = message.getFriendOnlineStatusChangeProtocol();
                    if (null == friendOnlineStatusChangeProtocol) return null;
                    event = onFriendOnlineStatusChangeAsTouristsReader(responseCode, isError(responseCode, error) ? error : friendOnlineStatusChangeProtocol.getStatusDetail(), friendOnlineStatusChangeProtocol.getTouristsFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_ONLINE_STATUS_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendOnlineStatusChangeProtocol == dataType) {
                    BusinessProtocolMessages.FriendOnlineStatusChangeProtocol friendOnlineStatusChangeProtocol = message.getFriendOnlineStatusChangeProtocol();
                    if (null == friendOnlineStatusChangeProtocol) return null;
                    event = onFriendOnlineStatusChangeAsRegisteredReader(responseCode, isError(responseCode, error) ? error : friendOnlineStatusChangeProtocol.getStatusDetail(), friendOnlineStatusChangeProtocol.getRegisteredFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_APPLY_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendChatProtocol == dataType) {
                    event = onFriendApplyAsTouristsReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "申请发送失败" : "申请发送成功");
                }
                break;
            case IMSContacts.MsgType.FRIEND_APPLY_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendChatProtocol == dataType) {
                    event = onFriendApplyAsRegisteredReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "申请发送失败" : "申请发送成功");
                }
                break;
            case IMSContacts.MsgType.FRIEND_APPLY_AGREE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendAddProtocol == dataType) {
                    BusinessProtocolMessages.FriendAddProtocol friendAddProtocol = message.getFriendAddProtocol();
                    if (null == friendAddProtocol) return null;
                    BusinessProtocolEntities.TouristsFriend tFriend = null;
                    List<BusinessProtocolEntities.TouristsFriend> touristsFriendList = friendAddProtocol.getTouristsFriendList();
                    for (BusinessProtocolEntities.TouristsFriend touristsFriend : touristsFriendList) {
                        if (!UserPreferences.getUserId().equals(touristsFriend.getFriendUserId())) {
                            tFriend = touristsFriend;
                            break;
                        }
                    }
                    event = onFriendApplyAgreeAsTouristsReader(responseCode, isError(responseCode, error) ? error : friendAddProtocol.getStatusDetail(), tFriend);
                }
                break;
            case IMSContacts.MsgType.FRIEND_APPLY_AGREE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendAddProtocol == dataType) {
                    BusinessProtocolMessages.FriendAddProtocol friendAddProtocol = message.getFriendAddProtocol();
                    if (null == friendAddProtocol) return null;
                    BusinessProtocolEntities.RegisteredFriend rFriend = null;
                    List<BusinessProtocolEntities.RegisteredFriend> registeredFriendList = friendAddProtocol.getRegisteredFriendList();
                    for (BusinessProtocolEntities.RegisteredFriend registeredFriend : registeredFriendList) {
                        if (!UserPreferences.getUserId().equals(registeredFriend.getFriendUserId())) {
                            rFriend = registeredFriend;
                            break;
                        }
                    }
                    event = onFriendApplyAgreeAsRegisteredReader(responseCode, isError(responseCode, error) ? error : friendAddProtocol.getStatusDetail(), rFriend);
                }
                break;
            case IMSContacts.MsgType.FRIEND_APPLY_REFUSE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendChatProtocol == dataType) {
                    event = onFriendApplyRefuseAsTouristsReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "发送失败" : "发送成功");
                }
                break;
            case IMSContacts.MsgType.FRIEND_APPLY_REFUSE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendChatProtocol == dataType) {
                    event = onFriendApplyRefuseAsRegisteredReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "发送失败" : "发送成功");
                }
                break;
            case IMSContacts.MsgType.FRIEND_DELETE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendDeleteProtocol == dataType) {
                    BusinessProtocolMessages.FriendDeleteProtocol friendDeleteProtocol = message.getFriendDeleteProtocol();
                    if (null == friendDeleteProtocol) return null;
                    event = onFriendDeleteAsTouristsReader(responseCode, isError(responseCode, error) ? error : friendDeleteProtocol.getStatusDetail(), friendDeleteProtocol.getTouristsFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_DELETE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendDeleteProtocol == dataType) {
                    BusinessProtocolMessages.FriendDeleteProtocol friendDeleteProtocol = message.getFriendDeleteProtocol();
                    if (null == friendDeleteProtocol) return null;
                    event = onFriendDeleteAsRegisteredReader(responseCode, isError(responseCode, error) ? error : friendDeleteProtocol.getStatusDetail(), friendDeleteProtocol.getRegisteredFriend());
                }
                break;
            case IMSContacts.MsgType.GROUP_FIND_TOURISTS:
            case IMSContacts.MsgType.GROUP_FIND_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FindGroupProtocol == dataType) {
                    BusinessProtocolMessages.FindGroupProtocol findGroupProtocol = message.getFindGroupProtocol();
                    if (null == findGroupProtocol) return null;
                    event = onGroupFindReader(responseCode, isError(responseCode, error) ? error : findGroupProtocol.getStatusDetail(), findGroupProtocol.getRegisteredGroupList(), findGroupProtocol.getTouristsGroupList());
                }
                break;
            case IMSContacts.MsgType.GROUP_LIST_TOURISTS:
            case IMSContacts.MsgType.GROUP_LIST_REGISTERED:
            case IMSContacts.MsgType.GROUP_LIST_NEW:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupListProtocol == dataType) {
                    BusinessProtocolMessages.GroupListProtocol groupListProtocol = message.getGroupListProtocol();
                    if (null == groupListProtocol) return null;
                    event = onGroupListReader(responseCode, isError(responseCode, error) ? error : groupListProtocol.getStatusDetail(), groupListProtocol.getRegisteredGroupList(), groupListProtocol.getTouristsGroupList());
                }
                break;
            case IMSContacts.MsgType.GROUP_CREATE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupCreateProtocol == dataType) {
                    BusinessProtocolMessages.GroupCreateProtocol groupCreateProtocol = message.getGroupCreateProtocol();
                    if (null == groupCreateProtocol) return null;
                    event = onGroupCreateAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupCreateProtocol.getStatusDetail(), groupCreateProtocol.getTouristsGroup());
//                    event = onGroupCreateAsReader(responseCode, isError(responseCode, error) ? error : groupCreateProtocol.getStatusDetail(), groupCreateProtocol.getAllGroupMemberVoList());
                }
                break;
            case IMSContacts.MsgType.GROUP_CREATE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupCreateProtocol == dataType) {
                    BusinessProtocolMessages.GroupCreateProtocol groupCreateProtocol = message.getGroupCreateProtocol();
                    if (null == groupCreateProtocol) return null;
                    event = onGroupCreateAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupCreateProtocol.getStatusDetail(), groupCreateProtocol.getRegisteredGroup());
//                    event = onGroupCreateAsReader(responseCode, isError(responseCode, error) ? error : groupCreateProtocol.getStatusDetail(), groupCreateProtocol.getAllGroupMemberVoList());
                }
                break;
            case IMSContacts.MsgType.GROUP_INFO_TOURISTS:
//                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupInfoProtocol == dataType) {
//                    BusinessProtocolMessages.GroupInfoProtocol groupInfoProtocol = message.getGroupInfoProtocol();
//                    if (null == groupInfoProtocol) return null;
//                    event = onGroupInfoAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupInfoProtocol.getStatusDetail(), groupInfoProtocol.getTouristsGroup(), groupInfoProtocol.getTouristsGroupMemberList());
//                }
//                break;
            case IMSContacts.MsgType.GROUP_INFO_REGISTERED:
            case IMSContacts.MsgType.GROUP_INFO_NEW:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupInfoProtocol == dataType) {
                    BusinessProtocolMessages.GroupInfoProtocol groupInfoProtocol = message.getGroupInfoProtocol();
                    if (null == groupInfoProtocol) return null;
                    String token = message.getHead().getToken();
                    String groupAvatar = groupInfoProtocol.getRegisteredGroup().getGroupAvatar();
                    event = onGroupInfoReader(responseCode, isError(responseCode, error) ? error : groupInfoProtocol.getStatusDetail(), groupInfoProtocol.getAllGroupMemberVoList(), token, groupAvatar);
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_ONLINE_STATUS_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberOnlineStatusChangeProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberOnlineStatusChangeProtocol groupMemberOnlineStatusChangeProtocol = message.getGroupMemberOnlineStatusChangeProtocol();
                    if (null == groupMemberOnlineStatusChangeProtocol) return null;
                    event = onGroupMemberOnlineStatusChangeAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupMemberOnlineStatusChangeProtocol.getStatusDetail(), groupMemberOnlineStatusChangeProtocol.getTouristsGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_ONLINE_STATUS_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberOnlineStatusChangeProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberOnlineStatusChangeProtocol groupMemberOnlineStatusChangeProtocol = message.getGroupMemberOnlineStatusChangeProtocol();
                    if (null == groupMemberOnlineStatusChangeProtocol) return null;
                    event = onGroupMemberOnlineStatusChangeAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupMemberOnlineStatusChangeProtocol.getStatusDetail(), groupMemberOnlineStatusChangeProtocol.getRegisteredGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_INVITE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberAddProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberAddProtocol groupMemberAddProtocol = message.getGroupMemberAddProtocol();
                    if (null == groupMemberAddProtocol) return null;
                    event = onGroupMemberInviteAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupMemberAddProtocol.getStatusDetail(), groupMemberAddProtocol.getTouristsGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_INVITE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberAddProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberAddProtocol groupMemberAddProtocol = message.getGroupMemberAddProtocol();
                    if (null == groupMemberAddProtocol) return null;
                    event = onGroupMemberInviteAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupMemberAddProtocol.getStatusDetail(), groupMemberAddProtocol.getRegisteredGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_INVITE_AGREE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberAddProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberAddProtocol groupMemberAddProtocol = message.getGroupMemberAddProtocol();
                    if (null == groupMemberAddProtocol) return null;
                    event = onGroupMemberInviteAgreeAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupMemberAddProtocol.getStatusDetail(), groupMemberAddProtocol.getTouristsGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_INVITE_AGREE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberAddProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberAddProtocol groupMemberAddProtocol = message.getGroupMemberAddProtocol();
                    if (null == groupMemberAddProtocol) return null;
                    event = onGroupMemberInviteAgreeAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupMemberAddProtocol.getStatusDetail(), groupMemberAddProtocol.getRegisteredGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_INVITE_REFUSE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberAddProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberAddProtocol groupMemberAddProtocol = message.getGroupMemberAddProtocol();
                    if (null == groupMemberAddProtocol) return null;
                    event = onGroupMemberInviteRefuseAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupMemberAddProtocol.getStatusDetail(), groupMemberAddProtocol.getTouristsGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_INVITE_REFUSE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberAddProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberAddProtocol groupMemberAddProtocol = message.getGroupMemberAddProtocol();
                    if (null == groupMemberAddProtocol) return null;
                    event = onGroupMemberInviteRefuseAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupMemberAddProtocol.getStatusDetail(), groupMemberAddProtocol.getRegisteredGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_APPLY_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupChatProtocol == dataType) {
                    event = onGroupMemberApplyAsTouristsReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "申请发送失败" : "申请发送成功");
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_APPLY_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupChatProtocol == dataType) {
                    event = onGroupMemberApplyAsRegisteredReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "申请发送失败" : "申请发送成功");
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_APPLY_AGREE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberAddProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberAddProtocol groupMemberAddProtocol = message.getGroupMemberAddProtocol();
                    if (null == groupMemberAddProtocol) return null;
                    event = onGroupMemberApplyAgreeAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupMemberAddProtocol.getStatusDetail(), groupMemberAddProtocol.getTouristsGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_APPLY_AGREE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberAddProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberAddProtocol groupMemberAddProtocol = message.getGroupMemberAddProtocol();
                    if (null == groupMemberAddProtocol) return null;
                    event = onGroupMemberApplyAgreeAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupMemberAddProtocol.getStatusDetail(), groupMemberAddProtocol.getRegisteredGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_APPLY_REFUSE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupChatProtocol == dataType) {
                    event = onGroupMemberApplyRefuseAsTouristsReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "申请发送失败" : "申请发送成功");
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_APPLY_REFUSE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupChatProtocol == dataType) {
                    event = onGroupMemberApplyRefuseAsRegisteredReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "申请发送失败" : "申请发送成功");
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_DELETE:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupChatProtocol == dataType) {
                    event = onGroupMemberDeleteReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "删除失败" : "成功移出群聊");
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_EXIT:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupChatProtocol == dataType) {
                    event = onGroupMemberExitReader(responseCode, isError(responseCode, error) ? error : IMSContacts.ResponseCode.SUCCESS != responseCode ? "删除失败" : "成功移出群聊");
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_DELETE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberDeleteProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberDeleteProtocol groupMemberDeleteProtocol = message.getGroupMemberDeleteProtocol();
                    if (null == groupMemberDeleteProtocol) return null;
                    event = onGroupMemberDeleteAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupMemberDeleteProtocol.getStatusDetail(), groupMemberDeleteProtocol.getTouristsGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_DELETE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberDeleteProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberDeleteProtocol groupMemberDeleteProtocol = message.getGroupMemberDeleteProtocol();
                    if (null == groupMemberDeleteProtocol) return null;
                    event = onGroupMemberDeleteAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupMemberDeleteProtocol.getStatusDetail(), groupMemberDeleteProtocol.getRegisteredGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_ANNOUNCEMENT_UPDATE_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupAnnouncementProtocol == dataType) {
                    BusinessProtocolMessages.GroupAnnouncementProtocol groupAnnouncementProtocol = message.getGroupAnnouncementProtocol();
                    if (null == groupAnnouncementProtocol) return null;
                    event = onGroupAnnouncementUpdateAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupAnnouncementProtocol.getStatusDetail(), groupAnnouncementProtocol.getTouristsGroup());
//                    int groupAnnouncementOpt = groupAnnouncementProtocol.getOperation();
//                    if (groupAnnouncementOpt == IMSContacts.Operation.EDIT_GROUP_ANNOUNCEMENT)
//                        event = onGroupAnnouncementUpdateAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupAnnouncementProtocol.getStatusDetail(), groupAnnouncementProtocol.getTouristsGroup());
//                    else if (groupAnnouncementOpt == IMSContacts.Operation.GET_GROUP_ANNOUNCEMENT)
//                        event = onGroupAnnouncementSelectAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupAnnouncementProtocol.getStatusDetail(), groupAnnouncementProtocol.getTouristsGroup());
                }
                break;
            case IMSContacts.MsgType.GROUP_ANNOUNCEMENT_UPDATE_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupAnnouncementProtocol == dataType) {
                    BusinessProtocolMessages.GroupAnnouncementProtocol groupAnnouncementProtocol = message.getGroupAnnouncementProtocol();
                    if (null == groupAnnouncementProtocol) return null;
                    event = onGroupAnnouncementUpdateAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupAnnouncementProtocol.getStatusDetail(), groupAnnouncementProtocol.getRegisteredGroup());

//                    int groupAnnouncementOpt = groupAnnouncementProtocol.getOperation();
//                    if (groupAnnouncementOpt == IMSContacts.Operation.EDIT_GROUP_ANNOUNCEMENT)
//                        event = onGroupAnnouncementUpdateAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupAnnouncementProtocol.getStatusDetail(), groupAnnouncementProtocol.getRegisteredGroup());
//                    else if (groupAnnouncementOpt == IMSContacts.Operation.GET_GROUP_ANNOUNCEMENT)
//                        event = onGroupAnnouncementSelectAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupAnnouncementProtocol.getStatusDetail(), groupAnnouncementProtocol.getRegisteredGroup());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_NICKNAME_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalInfoProtocol == dataType) {
                    BusinessProtocolMessages.PersonalInfoProtocol personalInfoProtocol = message.getPersonalInfoProtocol();
                    if (null == personalInfoProtocol) return null;
                    event = onPersonalNicknameAsTouristsReader(responseCode, isError(responseCode, error) ? error : personalInfoProtocol.getStatusDetail(), personalInfoProtocol.getTouristsUser());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_NICKNAME_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalInfoProtocol == dataType) {
                    BusinessProtocolMessages.PersonalInfoProtocol personalInfoProtocol = message.getPersonalInfoProtocol();
                    if (null == personalInfoProtocol) return null;
                    event = onPersonalNicknameAsRegisteredReader(responseCode, isError(responseCode, error) ? error : personalInfoProtocol.getStatusDetail(), personalInfoProtocol.getRegisteredUser());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_AVATAR_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalInfoProtocol == dataType) {
                    BusinessProtocolMessages.PersonalInfoProtocol personalInfoProtocol = message.getPersonalInfoProtocol();
                    if (null == personalInfoProtocol) return null;
                    event = onPersonalAvatarAsTouristsReader(responseCode, isError(responseCode, error) ? error : personalInfoProtocol.getStatusDetail(), personalInfoProtocol.getTouristsUser());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_AVATAR_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalInfoProtocol == dataType) {
                    BusinessProtocolMessages.PersonalInfoProtocol personalInfoProtocol = message.getPersonalInfoProtocol();
                    if (null == personalInfoProtocol) return null;
                    event = onPersonalAvatarAsRegisteredReader(responseCode, isError(responseCode, error) ? error : personalInfoProtocol.getStatusDetail(), personalInfoProtocol.getRegisteredUser());
                }
                break;
            case IMSContacts.MsgType.VERIFICATION_CODE:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalInfoProtocol == dataType) {
                    BusinessProtocolMessages.PersonalInfoProtocol personalInfoProtocol = message.getPersonalInfoProtocol();
                    if (null == personalInfoProtocol) return null;
                    event = onPersonalVerificationCodeReader(responseCode, isError(responseCode, error) ? error : personalInfoProtocol.getStatusDetail(), personalInfoProtocol.getRegisteredUser());
                }
                break;
            case IMSContacts.MsgType.RESET_SECRET_VERIFY:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalInfoProtocol == dataType) {
                    BusinessProtocolMessages.PersonalInfoProtocol personalInfoProtocol = message.getPersonalInfoProtocol();
                    if (null == personalInfoProtocol) return null;
                    event = onPersonalResetSecretVerifyReader(responseCode, isError(responseCode, error) ? error : personalInfoProtocol.getStatusDetail());
                }
                break;
            case IMSContacts.MsgType.RESET_SECRET:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalInfoProtocol == dataType) {
                    BusinessProtocolMessages.PersonalInfoProtocol personalInfoProtocol = message.getPersonalInfoProtocol();
                    if (null == personalInfoProtocol) return null;
                    event = onPersonalResetSecretReader(responseCode, isError(responseCode, error) ? error : personalInfoProtocol.getStatusDetail());
                }
                break;
            case IMSContacts.MsgType.SETUP_PHONE:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalInfoProtocol == dataType) {
                    BusinessProtocolMessages.PersonalInfoProtocol personalInfoProtocol = message.getPersonalInfoProtocol();
                    if (null == personalInfoProtocol) return null;
                    event = onPersonalSetupPhoneReader(responseCode, isError(responseCode, error) ? error : personalInfoProtocol.getStatusDetail(), personalInfoProtocol.getRegisteredUser());
                }
                break;
            case IMSContacts.MsgType.SETUP_PHONE_EDIT:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalInfoProtocol == dataType) {
                    BusinessProtocolMessages.PersonalInfoProtocol personalInfoProtocol = message.getPersonalInfoProtocol();
                    if (null == personalInfoProtocol) return null;
                    event = onPersonalEditPhoneReader(responseCode, isError(responseCode, error) ? error : personalInfoProtocol.getStatusDetail(), personalInfoProtocol.getRegisteredUser());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_OFFLINE_MSG_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalOfflineMsgAsTouristsReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_OFFLINE_MSG_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalOfflineMsgAsRegisteredReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_FRIEND_SNAPCHAT_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalFriendSnapchatAsTouristsReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_FRIEND_SNAPCHAT_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalFriendSnapchatAsRegisteredReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_FRIEND_SNAPCHAT_LENGTH_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalFriendSnapchatLengthAsTouristsReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_FRIEND_SNAPCHAT_LENGTH_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalFriendSnapchatLengthAsRegisteredReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_GROUP_SNAPCHAT_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalGroupSnapchatAsTouristsReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_GROUP_SNAPCHAT_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalGroupSnapchatAsRegisteredReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_GROUP_SNAPCHAT_LENGTH_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalGroupSnapchatLengthAsTouristsReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_GROUP_SNAPCHAT_LENGTH_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalGroupSnapchatLengthAsRegisteredReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_EXIT_CLEAN_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalExitCleanAsTouristsReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_EXIT_CLEAN_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalExitCleanAsRegisteredReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_TIMER_CLEAN_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalTimerCleanAsTouristsReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.PERSONAL_TIMER_CLEAN_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalTimerCleanAsRegisteredReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
            case IMSContacts.MsgType.FRIEND_ALIAS_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendSettingsProtocol == dataType) {
                    BusinessProtocolMessages.FriendSettingsProtocol friendSettingsProtocol = message.getFriendSettingsProtocol();
                    if (null == friendSettingsProtocol) return null;
                    event = onFriendAliasAsTouristsReader(responseCode, isError(responseCode, error) ? error : friendSettingsProtocol.getStatusDetail(), friendSettingsProtocol.getTouristsFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_ALIAS_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendSettingsProtocol == dataType) {
                    BusinessProtocolMessages.FriendSettingsProtocol friendSettingsProtocol = message.getFriendSettingsProtocol();
                    if (null == friendSettingsProtocol) return null;
                    event = onFriendAliasAsRegisteredsReader(responseCode, isError(responseCode, error) ? error : friendSettingsProtocol.getStatusDetail(), friendSettingsProtocol.getRegisteredFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_SNAPCHAT_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendSettingsProtocol == dataType) {
                    BusinessProtocolMessages.FriendSettingsProtocol friendSettingsProtocol = message.getFriendSettingsProtocol();
                    if (null == friendSettingsProtocol) return null;
                    event = onFriendSnapchatAsTouristsReader(responseCode, isError(responseCode, error) ? error : friendSettingsProtocol.getStatusDetail(), friendSettingsProtocol.getTouristsFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_SNAPCHAT_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendSettingsProtocol == dataType) {
                    BusinessProtocolMessages.FriendSettingsProtocol friendSettingsProtocol = message.getFriendSettingsProtocol();
                    if (null == friendSettingsProtocol) return null;
                    event = onFriendSnapchatAsRegisteredReader(responseCode, isError(responseCode, error) ? error : friendSettingsProtocol.getStatusDetail(), friendSettingsProtocol.getRegisteredFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_SNAPCHAT_LENGTH_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendSettingsProtocol == dataType) {
                    BusinessProtocolMessages.FriendSettingsProtocol friendSettingsProtocol = message.getFriendSettingsProtocol();
                    if (null == friendSettingsProtocol) return null;
                    event = onFriendSnapchatLengthAsTouristsReader(responseCode, isError(responseCode, error) ? error : friendSettingsProtocol.getStatusDetail(), friendSettingsProtocol.getTouristsFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_SNAPCHAT_LENGTH_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendSettingsProtocol == dataType) {
                    BusinessProtocolMessages.FriendSettingsProtocol friendSettingsProtocol = message.getFriendSettingsProtocol();
                    if (null == friendSettingsProtocol) return null;
                    event = onFriendSnapchatLengthAsRegisteredReader(responseCode, isError(responseCode, error) ? error : friendSettingsProtocol.getStatusDetail(), friendSettingsProtocol.getRegisteredFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_OFFLINE_MSG_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendSettingsProtocol == dataType) {
                    BusinessProtocolMessages.FriendSettingsProtocol friendSettingsProtocol = message.getFriendSettingsProtocol();
                    if (null == friendSettingsProtocol) return null;
                    event = onFriendOfflineMsgAsTouristsReader(responseCode, isError(responseCode, error) ? error : friendSettingsProtocol.getStatusDetail(), friendSettingsProtocol.getTouristsFriend());
                }
                break;
            case IMSContacts.MsgType.FRIEND_OFFLINE_MSG_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendSettingsProtocol == dataType) {
                    BusinessProtocolMessages.FriendSettingsProtocol friendSettingsProtocol = message.getFriendSettingsProtocol();
                    if (null == friendSettingsProtocol) return null;
                    event = onFriendOfflineMsgAsRegisteredReader(responseCode, isError(responseCode, error) ? error : friendSettingsProtocol.getStatusDetail(), friendSettingsProtocol.getRegisteredFriend());
                }
                break;
            case IMSContacts.MsgType.GROUP_NAME_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupSettingsProtocol == dataType) {
                    BusinessProtocolMessages.GroupSettingsProtocol groupSettingsProtocol = message.getGroupSettingsProtocol();
                    if (null == groupSettingsProtocol) return null;
                    event = onGroupNameAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupSettingsProtocol.getStatusDetail(), groupSettingsProtocol.getTouristsGroup());
                }
                break;
            case IMSContacts.MsgType.GROUP_NAME_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupSettingsProtocol == dataType) {
                    BusinessProtocolMessages.GroupSettingsProtocol groupSettingsProtocol = message.getGroupSettingsProtocol();
                    if (null == groupSettingsProtocol) return null;
                    event = onGroupNameAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupSettingsProtocol.getStatusDetail(), groupSettingsProtocol.getRegisteredGroup());
                }
                break;
            case IMSContacts.MsgType.GROUP_SNAPCHAT_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupSettingsProtocol == dataType) {
                    BusinessProtocolMessages.GroupSettingsProtocol groupSettingsProtocol = message.getGroupSettingsProtocol();
                    if (null == groupSettingsProtocol) return null;
                    event = onGroupSnapchatAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupSettingsProtocol.getStatusDetail(), groupSettingsProtocol.getTouristsGroup());
                }
                break;
            case IMSContacts.MsgType.GROUP_SNAPCHAT_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupSettingsProtocol == dataType) {
                    BusinessProtocolMessages.GroupSettingsProtocol groupSettingsProtocol = message.getGroupSettingsProtocol();
                    if (null == groupSettingsProtocol) return null;
                    event = onGroupSnapchatAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupSettingsProtocol.getStatusDetail(), groupSettingsProtocol.getRegisteredGroup());
                }
                break;
            case IMSContacts.MsgType.GROUP_SNAPCHAT_LENGTH_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupSettingsProtocol == dataType) {
                    BusinessProtocolMessages.GroupSettingsProtocol groupSettingsProtocol = message.getGroupSettingsProtocol();
                    if (null == groupSettingsProtocol) return null;
                    event = onGroupSnapchatLengthAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupSettingsProtocol.getStatusDetail(), groupSettingsProtocol.getTouristsGroup());
                }
                break;
            case IMSContacts.MsgType.GROUP_SNAPCHAT_LENGTH_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupSettingsProtocol == dataType) {
                    BusinessProtocolMessages.GroupSettingsProtocol groupSettingsProtocol = message.getGroupSettingsProtocol();
                    if (null == groupSettingsProtocol) return null;
                    event = onGroupSnapchatLengthAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupSettingsProtocol.getStatusDetail(), groupSettingsProtocol.getRegisteredGroup());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_NICK_TOURISTS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberSettingsProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberSettingsProtocol groupMemberSettingsProtocol = message.getGroupMemberSettingsProtocol();
                    if (null == groupMemberSettingsProtocol) return null;
                    event = onGroupMemberNickAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupMemberSettingsProtocol.getStatusDetail(), groupMemberSettingsProtocol.getTouristsGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_NICK_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberSettingsProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberSettingsProtocol groupMemberSettingsProtocol = message.getGroupMemberSettingsProtocol();
                    if (null == groupMemberSettingsProtocol) return null;
                    event = onGroupMemberNickAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupMemberSettingsProtocol.getStatusDetail(), groupMemberSettingsProtocol.getRegisteredGroupMember());
                }
                break;
            case IMSContacts.MsgType.GROUP_MEMBER_ALIAS:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberSettingsProtocol == dataType) {
                    BusinessProtocolMessages.GroupMemberSettingsProtocol groupMemberSettingsProtocol = message.getGroupMemberSettingsProtocol();
                    if (null == groupMemberSettingsProtocol) return null;
                    event = onGroupMemberAliasReader(responseCode, isError(responseCode, error) ? error : groupMemberSettingsProtocol.getStatusDetail(), groupMemberSettingsProtocol.getTouristsGroupMember(), groupMemberSettingsProtocol.getRegisteredGroupMember());
                }
                break;
//            case IMSContacts.MsgType.GROUP_MEMBER_ALIAS_TOURISTS:
//                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberSettingsProtocol == dataType) {
//                    BusinessProtocolMessages.GroupMemberSettingsProtocol groupMemberSettingsProtocol = message.getGroupMemberSettingsProtocol();
//                    if (null == groupMemberSettingsProtocol) return null;
//                    event = onGroupMemberAliasAsTouristsReader(responseCode, isError(responseCode, error) ? error : groupMemberSettingsProtocol.getStatusDetail(), groupMemberSettingsProtocol.getTouristsGroupMember());
//                }
//                break;
//            case IMSContacts.MsgType.GROUP_MEMBER_ALIAS_REGISTERED:
//                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupMemberSettingsProtocol == dataType) {
//                    BusinessProtocolMessages.GroupMemberSettingsProtocol groupMemberSettingsProtocol = message.getGroupMemberSettingsProtocol();
//                    if (null == groupMemberSettingsProtocol) return null;
//                    event = onGroupMemberAliasAsRegisteredReader(responseCode, isError(responseCode, error) ? error : groupMemberSettingsProtocol.getStatusDetail(), groupMemberSettingsProtocol.getRegisteredGroupMember());
//                }
//                break;
            case IMSContacts.MsgType.NOTIFICATIONS_TOURISTS:
//                    event = onNotificationsAsTouristsReader(responseCode, isError(responseCode, error) ? error : notificationsProtocol.getStatusDetail(), notificationsProtocol.getSysNotifyList(), notificationsProtocol.getTouristsNotifyList());
            case IMSContacts.MsgType.NOTIFICATIONS_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.NotificationsProtocol == dataType) {
                    BusinessProtocolMessages.NotificationsProtocol notificationsProtocol = message.getNotificationsProtocol();
                    if (null == notificationsProtocol) return null;
                    event = onNotificationsReader(responseCode, isError(responseCode, error) ? error : notificationsProtocol.getStatusDetail(), notificationsProtocol.getSysNotifyList());
//                    event = onNotificationsAsRegisteredReader(responseCode, isError(responseCode, error) ? error : notificationsProtocol.getStatusDetail(), notificationsProtocol.getSysNotifyList(), notificationsProtocol.getRegisteredNotifyList());
                }
                break;
            case IMSContacts.MsgType.FRIEND_CHAT_TOURISTS:
            case IMSContacts.MsgType.FRIEND_CHAT_REGISTERED:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.FriendChatProtocol == dataType) {
                    BusinessProtocolMessageStandard.Head head = message.getHead();
                    if (null == head) return null;
                    event = onFriendChatMessageReader(responseCode, "", head);
                }
                break;
            case IMSContacts.MsgType.GROUP_CHAT_TOURISTS:
            case IMSContacts.MsgType.GROUP_CHAT_REGISTERED:
            case IMSContacts.MsgType.GROUP_CHAT_NEW:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.GroupChatProtocol == dataType) {
                    BusinessProtocolMessageStandard.Head head = message.getHead();
                    if (null == head) return null;
                    event = onGroupChatMessageReader(responseCode, "", head);
                }
                break;
            case IMSContacts.MsgType.GET_OFF_MESSAGE_TOURIST:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.OffFriendMessageListProtocol == dataType) {
                    BusinessProtocolMessages.OffFriendMessageListProtocol offFriendMessageListProtocol = message.getOffFriendMessageListProtocol();
                    if (null == offFriendMessageListProtocol) return null;
                    event = onOffFriendMessageAsTouristsReader(responseCode, isError(responseCode, error) ? error : offFriendMessageListProtocol.getStatusDetail(), offFriendMessageListProtocol);
                }
                break;
            case IMSContacts.MsgType.GET_OFF_MESSAGE_REGIST:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.OffFriendMessageListProtocol == dataType) {
                    BusinessProtocolMessages.OffFriendMessageListProtocol offFriendMessageListProtocol = message.getOffFriendMessageListProtocol();
                    if (null == offFriendMessageListProtocol) return null;
                    event = onOffFriendMessageAsRegisteredReader(responseCode, isError(responseCode, error) ? error : offFriendMessageListProtocol.getStatusDetail(), offFriendMessageListProtocol);
                }
                break;
            case IMSContacts.MsgType.GROUP_CHART_OFF_LINE_MSG:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.OfflineGroupMessageProtocol == dataType) {
                    BusinessProtocolMessages.OfflineGroupMessageProtocol offlineGroupMessageProtocol = message.getOfflineGroupMessageProtocol();
                    if (null == offlineGroupMessageProtocol) return null;
                    event = onGroupOfflineMessageReader(responseCode, isError(responseCode, error) ? error : offlineGroupMessageProtocol.getStatusDetail(), offlineGroupMessageProtocol);
                }
                break;
            case IMSContacts.MsgType.CHECK_FOR_UPDATES:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.CheckForUpdatesProtocol == dataType) {
                    BusinessProtocolMessages.CheckForUpdatesProtocol checkForUpdatesProtocol = message.getCheckForUpdatesProtocol();
                    if (null == checkForUpdatesProtocol) return null;
                    event = onCheckForUpdatesReader(responseCode, isError(responseCode, error) ? error : "", checkForUpdatesProtocol);
                }
                break;
            case IMSContacts.MsgType.PERSONAL_SETTINGS_INFO:
                if (BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType.PersonalSettingsProtocol == dataType) {
                    BusinessProtocolMessages.PersonalSettingsProtocol personalSettingsProtocol = message.getPersonalSettingsProtocol();
                    if (null == personalSettingsProtocol) return null;
                    event = onPersonalSettingsInfoReader(responseCode, isError(responseCode, error) ? error : personalSettingsProtocol.getStatusDetail(), personalSettingsProtocol.getSettings());
                }
                break;
        }
        return event;
    }


//    private MessageEvent getMessageEvent(int responseCode, BusinessProtocolMessageStandard.UnifiedEntranceMessage.DataType dataType, BusinessProtocolMessageStandard.UnifiedEntranceMessage message) {
//        if (message == null) return null;
//        MessageEvent event = null;
//        switch (dataType) {
//            case FriendAddProtocol:
//                BusinessProtocolMessages.FriendAddProtocol friendAddProtocol = message.getFriendAddProtocol();
//                if (null == friendAddProtocol) return null;
//                int friendAddOpt = friendAddProtocol.getOperation();
//
//                BusinessProtocolEntities.TouristsFriend tFriend = null;
//                List<BusinessProtocolEntities.TouristsFriend> touristsFriendList = friendAddProtocol.getTouristsFriendList();
//                for (BusinessProtocolEntities.TouristsFriend touristsFriend : touristsFriendList) {
//                    if (!UserPreferences.getUserId().equals(touristsFriend.getFriendUserId())) {
//                        tFriend = touristsFriend;
//                        break;
//                    }
//                }
//                BusinessProtocolEntities.RegisteredFriend rFriend = null;
//                List<BusinessProtocolEntities.RegisteredFriend> registeredFriendList = friendAddProtocol.getRegisteredFriendList();
//                for (BusinessProtocolEntities.RegisteredFriend registeredFriend : registeredFriendList) {
//                    if (!UserPreferences.getUserId().equals(registeredFriend.getFriendUserId())) {
//                        rFriend = registeredFriend;
//                        break;
//                    }
//                }
//
//                if (friendAddOpt == IMSContacts.Operation.APPLY) {
//                    if (null != tFriend)
//                        event = onFriendApplyAsTouristsReader(responseCode, friendAddProtocol.getStatusDetail(), tFriend);
//                    if (null != rFriend)
//                        event = onFriendApplyAsRegisteredReader(responseCode, friendAddProtocol.getStatusDetail(), rFriend);
//                } else if (friendAddOpt == IMSContacts.Operation.AGREE) {
//                    if (null != tFriend)
//                        event = onFriendApplyAgreeAsTouristsReader(responseCode, friendAddProtocol.getStatusDetail(), tFriend);
//                    if (null != rFriend)
//                        event = onFriendApplyAgreeAsRegisteredReader(responseCode, friendAddProtocol.getStatusDetail(), rFriend);
//                } else if (friendAddOpt == IMSContacts.Operation.REFUSE) {
//                    if (null != tFriend)
//                        event = onFriendApplyRefuseAsTouristsReader(responseCode, friendAddProtocol.getStatusDetail(), tFriend);
//                    if (null != rFriend)
//                        event = onFriendApplyRefuseAsRegisteredReader(responseCode, friendAddProtocol.getStatusDetail(), rFriend);
//                }
//                break;
//            case SysNotifyProtocol:
//                BusinessProtocolMessages.SysNotifyProtocol sysNotifyProtocol = message.getSysNotifyProtocol();
//                if (null == sysNotifyProtocol) return null;
//                event = onSysNotificationsReader(responseCode, sysNotifyProtocol.getStatusDetail(), sysNotifyProtocol.getSysNotify());
//                break;
//            case UserNotifyProtocol:
//                BusinessProtocolMessages.UserNotifyProtocol userNotifyProtocol = message.getUserNotifyProtocol();
//                if (null == userNotifyProtocol) return null;
//                if (IMSContacts.UserType.TOURISTS_USER.equals(userNotifyProtocol.getUserType())) {
//                    event = onUserNotificationsAsTouristsReader(responseCode, userNotifyProtocol.getStatusDetail(), userNotifyProtocol.getTouristsNotify());
//                } else {
//                    event = onUserNotificationsAsRegisteredReader(responseCode, userNotifyProtocol.getStatusDetail(), userNotifyProtocol.getRegisteredNotify());
//                }
//                break;
//            case FriendChatProtocol:
//                BusinessProtocolMessages.FriendChatProtocol friendChatProtocol = message.getFriendChatProtocol();
//                if (null == friendChatProtocol) return null;
//                event = onFriendChatMessageReader(responseCode, friendChatProtocol.getStatusDetail(), message);
//                break;
//            case GroupChatProtocol:
//                BusinessProtocolMessages.GroupChatProtocol groupChatProtocol = message.getGroupChatProtocol();
//                if (null == groupChatProtocol) return null;
//                event = onGroupChatMessageReader(responseCode, groupChatProtocol.getStatusDetail(), message);
//                break;
//        }
//        return event;
//    }

    // 注册
    private MessageEvent onRegisterResponseReader(int code, String msg, BusinessProtocolEntities.RegisteredUser registeredUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.REGISTER);
        event.setResponse(code, msg);
        if (IMSContacts.ResponseCode.SUCCESS == code) {
            if (null != registeredUser) {
                RegisteredUserDto userDto = new RegisteredUserDto(registeredUser);
                event.setData(userDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "注册失败");
            }
        }
        return event;
    }

    // 游客登录
    private MessageEvent onLoginAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsUser touristsUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.LOGIN_TOURISTS);
        event.setResponse(code, msg);
        if (IMSContacts.ResponseCode.SUCCESS == code) {
            if (null != touristsUser) {
                TouristsUserDto userDto = new TouristsUserDto(touristsUser);
                event.setData(userDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "登录失败");
            }
        }
        return event;
    }

    // 注册用户登录
    private MessageEvent onLoginAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredUser registeredUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.LOGIN_REGISTERED);
        event.setResponse(code, msg);
        if (IMSContacts.ResponseCode.SUCCESS == code) {
            if (null != registeredUser) {
                RegisteredUserDto userDto = new RegisteredUserDto(registeredUser);
                event.setData(userDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "登录失败");
            }
        }
        return event;
    }

    // 游客登出
    private MessageEvent onLogoutAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsUser touristsUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.LOGOUT_TOURISTS);
        event.setResponse(code, msg);
        if (null != touristsUser) {
            TouristsUserDto userDto = new TouristsUserDto(touristsUser);
            event.setData(userDto.getTemporaryId());
        }
        return event;
    }

    // 注册用户登出
    private MessageEvent onLogoutAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredUser registeredUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.LOGOUT_REGISTERED);
        event.setResponse(code, msg);
        if (null != registeredUser) {
            RegisteredUserDto userDto = new RegisteredUserDto(registeredUser);
            event.setData(userDto.getUserId());
        }
        return event;
    }

    // 查找好友(游客)
    private MessageEvent onFriendFindAsTouristsReader(int code, String msg, List<BusinessProtocolEntities.RegisteredUser> registeredUserList, List<BusinessProtocolEntities.TouristsUser> touristsUserList) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_FIND_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (CollectionUtils.isEmpty(registeredUserList) && CollectionUtils.isEmpty(touristsUserList)) {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "未找到结果");
            } else {
                List<RegisteredUserDto> registeredUserDtoList = null;
                if (!CollectionUtils.isEmpty(registeredUserList)) {
                    registeredUserDtoList = new ArrayList<>();
                    for (BusinessProtocolEntities.RegisteredUser registeredUser : registeredUserList)
                        registeredUserDtoList.add(new RegisteredUserDto(registeredUser));
                }
                List<TouristsUserDto> touristsUserDtoList = null;
                if (!CollectionUtils.isEmpty(touristsUserList)) {
                    touristsUserDtoList = new ArrayList<>();
                    for (BusinessProtocolEntities.TouristsUser touristsUser : touristsUserList)
                        touristsUserDtoList.add(new TouristsUserDto(touristsUser));
                }
                SearchResultDto resultDto = new SearchResultDto(registeredUserDtoList, touristsUserDtoList);
                event.setData(resultDto.toJson());
            }
        }
        return event;
    }

    // 查找好友(注册用户)
    private MessageEvent onFriendFindAsRegisteredReader(int code, String msg, List<BusinessProtocolEntities.RegisteredUser> registeredUserList, List<BusinessProtocolEntities.TouristsUser> touristsUserList) {
        MessageEvent event = onFriendFindAsTouristsReader(code, msg, registeredUserList, touristsUserList);
        event.setAction(EventConstants.Action.FRIEND_FIND_REGISTERED);
        return event;
    }

    // 获取好友列表
    private MessageEvent onFriendListReader(int code, String msg, List<BusinessProtocolEntities.RegisteredFriend> registeredFriendList, List<BusinessProtocolEntities.TouristsFriend> touristsFriendList) {
        MessageEvent event = MessageEvent.createReaderEvent(UserPreferences.isRegistered() ? EventConstants.Action.FRIEND_LIST_REGISTERED : EventConstants.Action.FRIEND_LIST_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            List<FriendDto> friendDtoList = new ArrayList<>();
            if (!CollectionUtils.isEmpty(registeredFriendList)) {
                for (BusinessProtocolEntities.RegisteredFriend registeredFriend : registeredFriendList) {
                    FriendDto friendDto = new FriendDto(registeredFriend);
                    friendDto.setUserType(IMSUtils.userTypeAnalysis(friendDto.getFriendUserId()));
                    friendDtoList.add(friendDto);
                }
            }
            if (!CollectionUtils.isEmpty(touristsFriendList)) {
                for (BusinessProtocolEntities.TouristsFriend touristsFriend : touristsFriendList) {
                    FriendDto friendDto = new FriendDto(touristsFriend);
                    friendDto.setUserType(IMSUtils.userTypeAnalysis(friendDto.getFriendUserId()));
                    friendDtoList.add(new FriendDto(touristsFriend));
                }
            }
            event.setData(JsonUtils.convertListToJson(friendDtoList));
        }
        return event;
    }

//    // 获取好友列表(游客)
//    private MessageEvent onFriendListAsTouristsReader(int code, String msg, List<BusinessProtocolEntities.TouristsFriend> touristsFriendList) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_LIST_TOURISTS);
//        event.setResponse(code, msg);
//        if (code == IMSContacts.ResponseCode.SUCCESS) {
//            if (!CollectionUtils.isEmpty(touristsFriendList)) {
//                List<FriendDto> touristsFriendDtoList = new ArrayList<>();
//                for (BusinessProtocolEntities.TouristsFriend touristsFriend : touristsFriendList)
//                    touristsFriendDtoList.add(new FriendDto(touristsFriend));
//                event.setData(JsonUtils.convertListToJson(touristsFriendDtoList));
//            } else {
//                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "暂无好友");
//            }
//        }
//        return event;
//    }
//
//    // 获取好友列表(注册用户)
//    private MessageEvent onFriendListAsRegisteredReader(int code, String msg, List<BusinessProtocolEntities.RegisteredFriend> registeredFriendList) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_LIST_REGISTERED);
//        event.setResponse(code, msg);
//        if (code == IMSContacts.ResponseCode.SUCCESS) {
//            if (!CollectionUtils.isEmpty(registeredFriendList)) {
//                List<FriendDto> registeredFriendDtoList = new ArrayList<>();
//                for (BusinessProtocolEntities.RegisteredFriend registeredFriend : registeredFriendList)
//                    registeredFriendDtoList.add(new FriendDto(registeredFriend));
//                event.setData(JsonUtils.convertListToJson(registeredFriendDtoList));
//            } else {
//                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "暂无好友");
//            }
//        }
//        return event;
//    }

    // 好友资料(游客)
    private MessageEvent onFriendInfoAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_INFO_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "资料更新失败");
            }
        }
        return event;
    }

    // 好友资料(注册用户)
    private MessageEvent onFriendInfoAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_INFO_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "资料更新失败");
            }
        }
        return event;
    }

    // 更新好友在线状态(游客)
    private MessageEvent onFriendOnlineStatusChangeAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_ONLINE_STATUS_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "状态更新失败");
            }
        }
        return event;
    }

    // 更新好友在线状态(注册用户)
    private MessageEvent onFriendOnlineStatusChangeAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_ONLINE_STATUS_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "状态更新失败");
            }
        }
        return event;
    }

    // 申请加好友(游客)
    private MessageEvent onFriendApplyAsTouristsReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_TOURISTS);
        event.setResponse(code, msg);
        return event;
    }

    private MessageEvent onFriendApplyAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, msg);
            }
        }
        return event;
    }

    // 申请加好友(注册用户)
    private MessageEvent onFriendApplyAsRegisteredReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_REGISTERED);
        event.setResponse(code, msg);
        return event;
    }

    private MessageEvent onFriendApplyAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, msg);
            }
        }
        return event;
    }

    // 同意好友申请(游客)
    private MessageEvent onFriendApplyAgreeAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_AGREE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            }
        }
        return event;
    }

    // 同意好友申请(注册用户)
    private MessageEvent onFriendApplyAgreeAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_AGREE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            }
        }
        return event;
    }

    // 拒绝好友申请(游客)
    private MessageEvent onFriendApplyRefuseAsTouristsReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_REFUSE_TOURISTS);
        event.setResponse(code, msg);
        return event;
    }

    private MessageEvent onFriendApplyRefuseAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_REFUSE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, msg);
            }
        }
        return event;
    }

    // 拒绝好友申请(注册用户)
    private MessageEvent onFriendApplyRefuseAsRegisteredReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_REFUSE_REGISTERED);
        event.setResponse(code, msg);
        return event;
    }

    private MessageEvent onFriendApplyRefuseAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_APPLY_REFUSE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, msg);
            }
        }
        return event;
    }

    // 删除好友(游客)
    private MessageEvent onFriendDeleteAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_DELETE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, msg);
            }
        }
        return event;
    }

    // 删除好友(注册用户)
    private MessageEvent onFriendDeleteAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_DELETE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, msg);
            }
        }
        return event;
    }

    private MessageEvent onGroupFindReader(int code, String msg, List<BusinessProtocolEntities.RegisteredGroup> rGroupList, List<BusinessProtocolEntities.TouristsGroup> tGroupList) {
        MessageEvent event = MessageEvent.createReaderEvent(UserPreferences.isRegistered() ? EventConstants.Action.GROUP_FIND_REGISTERED : EventConstants.Action.GROUP_FIND_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            List<GroupDto> groupDtoList = new ArrayList<>();
            if (!CollectionUtils.isEmpty(rGroupList)) {
                for (BusinessProtocolEntities.RegisteredGroup registeredGroup : rGroupList)
                    groupDtoList.add(new GroupDto(registeredGroup));
            }
            if (!CollectionUtils.isEmpty(tGroupList)) {
                for (BusinessProtocolEntities.TouristsGroup touristsGroup : tGroupList)
                    groupDtoList.add(new GroupDto(touristsGroup));
            }
            event.setData(JsonUtils.convertListToJson(groupDtoList));
        }
        return event;
    }

//    // 查找群组(游客)
//    private MessageEvent onGroupFindAsTouristsReader(int code, String msg, List<BusinessProtocolEntities.TouristsGroup> groupList) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_FIND_TOURISTS);
//        event.setResponse(code, msg);
//        if (code == IMSContacts.ResponseCode.SUCCESS) {
//            if (!CollectionUtils.isEmpty(groupList)) {
//                List<GroupDto> groupDtoList = new ArrayList<>();
//                for (BusinessProtocolEntities.TouristsGroup touristsGroup : groupList)
//                    groupDtoList.add(new GroupDto(touristsGroup));
//                event.setData(JsonUtils.convertListToJson(groupDtoList));
//            } else {
//                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "暂无群组");
//            }
//        }
//        return event;
//    }
//
//    // 查找群组(注册用户)
//    private MessageEvent onGroupFindAsRegisteredReader(int code, String msg, List<BusinessProtocolEntities.RegisteredGroup> groupList) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_FIND_REGISTERED);
//        event.setResponse(code, msg);
//        if (code == IMSContacts.ResponseCode.SUCCESS) {
//            if (!CollectionUtils.isEmpty(groupList)) {
//                List<GroupDto> groupDtoList = new ArrayList<>();
//                for (BusinessProtocolEntities.RegisteredGroup registeredGroup : groupList)
//                    groupDtoList.add(new GroupDto(registeredGroup));
//                event.setData(JsonUtils.convertListToJson(groupDtoList));
//            } else {
//                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "暂无群组");
//            }
//        }
//        return event;
//    }

    private MessageEvent onGroupListReader(int code, String msg, List<BusinessProtocolEntities.RegisteredGroup> rGroupList, List<BusinessProtocolEntities.TouristsGroup> tGroupList) {
        MessageEvent event = MessageEvent.createReaderEvent(UserPreferences.isRegistered() ? EventConstants.Action.GROUP_LIST_REGISTERED : EventConstants.Action.GROUP_LIST_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            List<GroupDto> groupDtoList = new ArrayList<>();
            if (!CollectionUtils.isEmpty(rGroupList)) {
                for (BusinessProtocolEntities.RegisteredGroup registeredGroup : rGroupList)
                    groupDtoList.add(new GroupDto(registeredGroup));
            }
            if (!CollectionUtils.isEmpty(rGroupList)) {
                for (BusinessProtocolEntities.TouristsGroup touristsGroup : tGroupList)
                    groupDtoList.add(new GroupDto(touristsGroup));
            }
            if (groupDtoList.size() > 0)
                event.setData(JsonUtils.convertListToJson(groupDtoList));
        }
        return event;
    }

//    // 获取群组列表(游客)
//    private MessageEvent onGroupListAsTouristsReader(int code, String msg, List<BusinessProtocolEntities.TouristsGroup> groupList) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_LIST_TOURISTS);
//        event.setResponse(code, msg);
//        if (code == IMSContacts.ResponseCode.SUCCESS) {
//            if (!CollectionUtils.isEmpty(groupList)) {
//                List<GroupDto> groupDtoList = new ArrayList<>();
//                for (BusinessProtocolEntities.TouristsGroup touristsGroup : groupList)
//                    groupDtoList.add(new GroupDto(touristsGroup));
//                event.setData(JsonUtils.convertListToJson(groupDtoList));
//            } else {
//                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "暂无群组");
//            }
//        }
//        return event;
//    }
//
//    // 获取群组列表(注册用户)
//    private MessageEvent onGroupListAsRegisteredReader(int code, String msg, List<BusinessProtocolEntities.RegisteredGroup> groupList) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_LIST_REGISTERED);
//        event.setResponse(code, msg);
//        if (code == IMSContacts.ResponseCode.SUCCESS) {
//            if (!CollectionUtils.isEmpty(groupList)) {
//                List<GroupDto> groupDtoList = new ArrayList<>();
//                for (BusinessProtocolEntities.RegisteredGroup registeredGroup : groupList)
//                    groupDtoList.add(new GroupDto(registeredGroup));
//                event.setData(JsonUtils.convertListToJson(groupDtoList));
//            } else {
//                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "暂无群组");
//            }
//        }
//        return event;
//    }

    // 创建群
//    private MessageEvent onGroupCreateAsReader(int code, String msg, List<BusinessProtocolEntities.AllGroupMemberVO> groupMemberVOList) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_CREATE_TOURISTS);
//        event.setResponse(code, msg);
//        if (code == IMSContacts.ResponseCode.SUCCESS) {
//            GroupVo gvo = new GroupVo();
//            List<GroupVo.GroupMemberVo> gmvoList = new ArrayList<>();
//            for (int i = 0; i < groupMemberVOList.size(); i++) {
//                BusinessProtocolEntities.AllGroupMemberVO groupMemberVO = groupMemberVOList.get(i);
//                if (i == 0) {
//                    if (groupMemberVO.getGuestGroupId() != 0)
//                        gvo.setGroupId(groupMemberVO.getGuestGroupId());
//                    if (groupMemberVO.getRegisteredGroupId() != 0)
//                        gvo.setGroupId(groupMemberVO.getRegisteredGroupId());
//                    gvo.setGroupType(IMSUtils.userTypeAnalysis(String.valueOf(gvo.getGroupId())));
//                    gvo.setName(groupMemberVO.getGroupName());
//                    gvo.setRemarks(groupMemberVO.getGroupRemarks());
//                    gvo.setAmount(groupMemberVO.getAmount());
//                    gvo.setAnnouncement(groupMemberVO.getAnnouncementContent());
//                }
//                if ("Yes".equalsIgnoreCase(groupMemberVO.getGroupOwner())) {
//                    if (groupMemberVO.getGuestUserId() != 0)
//                        gvo.setOwner(String.valueOf(groupMemberVO.getGuestUserId()));
//                    if (groupMemberVO.getRegisteredUserId() != 0)
//                        gvo.setOwner(String.valueOf(groupMemberVO.getRegisteredUserId()));
//                }
//                GroupVo.GroupMemberVo gmvo = gvo.new GroupMemberVo();
//                gmvo.setGroupMemberId(groupMemberVO.getGroupMemberId());
//                if (groupMemberVO.getGuestUserId() != 0)
//                    gmvo.setMemberUserId(String.valueOf(groupMemberVO.getGuestUserId()));
//                if (groupMemberVO.getRegisteredUserId() != 0)
//                    gmvo.setMemberUserId(String.valueOf(groupMemberVO.getRegisteredUserId()));
//                gmvo.setMemberUserType(IMSUtils.userTypeAnalysis(gmvo.getMemberUserId()));
//                gmvo.setEntryTime(groupMemberVO.getGroupEntryTime());
//                if (!TextUtils.isEmpty(groupMemberVO.getGuestUserNickAme()))
//                    gmvo.setMemberNickname(groupMemberVO.getGuestUserNickAme());
//                if (!TextUtils.isEmpty(groupMemberVO.getRegisterUserNickAme()))
//                    gmvo.setMemberNickname(groupMemberVO.getRegisterUserNickAme());
//                gmvo.setMemberUserPhoto(groupMemberVO.getUserPhoto());
//                gmvoList.add(gmvo);
//            }
//            gvo.setGroupMembers(gmvoList);
//            event.setData(gvo.toJson());
//        }
//        return event;
//    }

    // 创建群(游客)
    private MessageEvent onGroupCreateAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_CREATE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "创建群组失败");
            }
        }
        return event;
    }

    // 创建群(注册用户)
    private MessageEvent onGroupCreateAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_CREATE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "创建群组失败");
            }
        }
        return event;
    }

    // 群资料
    private MessageEvent onGroupInfoReader(int code, String msg, List<BusinessProtocolEntities.AllGroupMemberVO> groupMemberVOList, String token, String group_avatar) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_INFO_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            GroupVo gvo = new GroupVo();
            List<GroupVo.GroupMemberVo> gmvoList = new ArrayList<>();
            GroupTable groupTable = null;
            for (int i = 0; i < groupMemberVOList.size(); i++) {
                BusinessProtocolEntities.AllGroupMemberVO groupMemberVO = groupMemberVOList.get(i);
                if (i == 0) {
                    if (groupMemberVO.getGuestGroupId() != 0)
                        gvo.setGroupId(groupMemberVO.getGuestGroupId());
                    if (groupMemberVO.getRegisteredGroupId() != 0)
                        gvo.setGroupId(groupMemberVO.getRegisteredGroupId());
                    gvo.setGroupType(IMSUtils.userTypeAnalysis(String.valueOf(gvo.getGroupId())));

                    gvo.setName(groupMemberVO.getGroupName());
                    gvo.setRemarks(groupMemberVO.getGroupRemarks());
                    gvo.setAmount(groupMemberVO.getAmount());
                    gvo.setAnnouncement(groupMemberVO.getAnnouncementContent());

                    // 更新群资料
                    groupTable = GroupTable.queryRowByGroupId(String.valueOf(gvo.getGroupId()));
                    if (groupTable == null) groupTable = new GroupTable();
                    groupTable.setGroupId(String.valueOf(gvo.getGroupId()));
                    groupTable.setGroupName(gvo.getName());
                    groupTable.setGroupType(gvo.getGroupType());
                    if (!TextUtils.isEmpty(group_avatar))
                        groupTable.setGroupAvatar(group_avatar);
                    groupTable.setAnnouncementContent(gvo.getAnnouncement());
                    groupTable.setMemberCount(gvo.getAmount());

                    GroupMemberTable.deleteByGroupId(String.valueOf(gvo.getGroupId()));
                }
                if ("Yes".equalsIgnoreCase(groupMemberVO.getGroupOwner())) {
                    if (groupMemberVO.getGuestUserId() != 0)
                        gvo.setOwner(String.valueOf(groupMemberVO.getGuestUserId()));
                    if (groupMemberVO.getRegisteredUserId() != 0)
                        gvo.setOwner(String.valueOf(groupMemberVO.getRegisteredUserId()));
                    groupTable.setGroupOwnerId(gvo.getOwner());
                    GroupTable.insert(groupTable);
                }
                GroupVo.GroupMemberVo gmvo = gvo.new GroupMemberVo();
                gmvo.setGroupMemberId(groupMemberVO.getGroupMemberId());
                if (groupMemberVO.getGuestUserId() != 0)
                    gmvo.setMemberUserId(String.valueOf(groupMemberVO.getGuestUserId()));
                if (groupMemberVO.getRegisteredUserId() != 0)
                    gmvo.setMemberUserId(String.valueOf(groupMemberVO.getRegisteredUserId()));
                gmvo.setMemberUserType(IMSUtils.userTypeAnalysis(gmvo.getMemberUserId()));
                gmvo.setEntryTime(groupMemberVO.getGroupEntryTime());
                if (!TextUtils.isEmpty(groupMemberVO.getGuestUserNickAme()))
                    gmvo.setMemberNickname(groupMemberVO.getGuestUserNickAme());
                if (!TextUtils.isEmpty(groupMemberVO.getRegisterUserNickAme()))
                    gmvo.setMemberNickname(groupMemberVO.getRegisterUserNickAme());
                gmvo.setMemberUserPhoto(groupMemberVO.getUserPhoto());
                gmvo.setMemberAlias(groupMemberVO.getGroupRemarks());
                gmvoList.add(gmvo);
                // 保存群成员资料
                GroupMemberTable mTable = GroupMemberTable.create(String.valueOf(gvo.getGroupId()), gmvo.getMemberUserId());
                mTable.setGroupId(String.valueOf(gvo.getGroupId()));
                mTable.setGroupMemberId(String.valueOf(gmvo.getGroupMemberId()));
                if (TextUtils.isEmpty(mTable.getGroupMemberAvatar()) || !mTable.getGroupMemberAvatar().equals(gmvo.getMemberUserPhoto())) {
                    mTable.setGroupMemberAvatar(gmvo.getMemberUserPhoto());
                    mTable.setGroupMemberAvatarId(null);
                    mTable.setGroupMemberAvatarPath(null);
                    AlbumTableBean fileTableByPath = AlbumManageUtil.getFileTableByPath(gmvo.getMemberUserPhoto());
                    if (fileTableByPath != null) {
                        AlbumTableBean.delete(fileTableByPath.getId());
                    }
                }
                mTable.setGroupMemberUserId(gmvo.getMemberUserId());
                mTable.setGroupMemberName(gmvo.getMemberNickname());
                mTable.setGroupMemberAlias(gmvo.getMemberAlias());
                mTable.setGroupMemberType(gmvo.getMemberUserId().equals(gvo.getOwner()) ? 1 : 0);
                mTable.setUserType(gmvo.getMemberUserType());
                GroupMemberTable.insertOrUpdate(mTable);

                ChatTableBean.updateGroupMemberAvatar(String.valueOf(gvo.getGroupId()), gmvo.getMemberUserId(), gmvo.getMemberUserPhoto());
            }
            gvo.setGroupMembers(gmvoList);
//            queryRowByTargetIdNotNull
            if (!TextUtils.isEmpty(group_avatar)) {
                ChatContentTable cct = ChatContentTable.queryRowByTargetId(String.valueOf(gvo.getGroupId()), Canstants.GROUP_CHAT);
                if (cct != null) {
                    cct.setChatType(Canstants.GROUP_CHAT);
                    cct.setTargetId(String.valueOf(gvo.getGroupId()));
                    cct.setTargetName(gvo.getName());
                    cct.setTargetType(gvo.getGroupType());
                    if (groupTable != null && !TextUtils.isEmpty(groupTable.getGroupAvatar())) {
                        cct.setTargetMemberUserId(groupTable.getGroupId());
                        cct.setTargetAvatarUrl(groupTable.getGroupAvatar());
                    } else {
                        String[] v = GroupMemberTable.getAvatarEntityLoc(String.valueOf(gvo.getGroupId()));
                        if (v != null) {
                            cct.setTargetMemberUserId(v[0]);
                            cct.setTargetAvatarUrl(v[1]);
                            cct.setTargetAvatarPath(v[2]);
                        }
                    }
                    ChatContentTable.insertNotUpdateNumber(cct);
                }
            }

            EventBus.getDefault().post(MessageEvent.cerateUiRefresh(EventConstants.Action.GROUP_REFRESH));
            event.setData(gvo.toJson());

            if (IMSContacts.Contact.NEW_GROUP.equals(token)) {
                IMSRequester.sendGroupHi(String.valueOf(gvo.getGroupId()), gvo.getName());
            }
            SharedPreferenceHelper.create(SPKeys.Name.CONFIG).setBoolean(SPKeys.Key.CONFIG_GROUP_MEMBER_REQUESTED + gvo.getGroupId(), true);
        }
        return event;
    }

//    // 群资料(游客)
//    private MessageEvent onGroupInfoAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroup group, List<BusinessProtocolEntities.TouristsGroupMember> groupMemberList) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_INFO_TOURISTS);
//        event.setResponse(code, msg);
//        if (null == group && CollectionUtils.isEmpty(groupMemberList)) {
//            event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "群组资料更新失败");
//        } else {
//            GroupDto groupDto = null;
//            if (null != group)
//                groupDto = new GroupDto(group);
//            List<GroupMemberDto> groupMemberDtoList = null;
//            if (!CollectionUtils.isEmpty(groupMemberList)) {
//                groupMemberDtoList = new ArrayList<>();
//                for (BusinessProtocolEntities.TouristsGroupMember touristsGroupMember : groupMemberList)
//                    groupMemberDtoList.add(new GroupMemberDto(touristsGroupMember));
//            }
//            GroupInfoDto groupInfoDto = new GroupInfoDto(groupDto, groupMemberDtoList);
//            event.setData(groupInfoDto.toJson());
//        }
//        return event;
//    }
//
//    // 群资料(注册用户)
//    private MessageEvent onGroupInfoAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroup group, List<BusinessProtocolEntities.RegisteredGroupMember> groupMemberList) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_INFO_REGISTERED);
//        event.setResponse(code, msg);
//        if (null == group && CollectionUtils.isEmpty(groupMemberList)) {
//            event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "群组资料更新失败");
//        } else {
//            GroupDto groupDto = null;
//            if (null != group)
//                groupDto = new GroupDto(group);
//            List<GroupMemberDto> groupMemberDtoList = null;
//            if (!CollectionUtils.isEmpty(groupMemberList)) {
//                groupMemberDtoList = new ArrayList<>();
//                for (BusinessProtocolEntities.RegisteredGroupMember registeredGroupMember : groupMemberList)
//                    groupMemberDtoList.add(new GroupMemberDto(registeredGroupMember));
//            }
//            GroupInfoDto groupInfoDto = new GroupInfoDto(groupDto, groupMemberDtoList);
//            event.setData(groupInfoDto.toJson());
//        }
//        return event;
//    }

    // 更新群成员在线状态(游客)
    private MessageEvent onGroupMemberOnlineStatusChangeAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_ONLINE_STATUS_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "状态更新失败");
            }
        }
        return event;
    }

    // 更新群成员在线状态(注册用户)
    private MessageEvent onGroupMemberOnlineStatusChangeAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_ONLINE_STATUS_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "状态更新失败");
            }
        }
        return event;
    }

    // 邀请入群(游客)
    private MessageEvent onGroupMemberInviteAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_INVITE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            }
        }
        return event;
    }

    // 邀请入群(注册用户)
    private MessageEvent onGroupMemberInviteAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_INVITE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            }
        }
        return event;
    }

    // 同意邀请(游客)
    private MessageEvent onGroupMemberInviteAgreeAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_INVITE_AGREE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "发送失败");
            }
        }
        return event;
    }

    // 同意邀请(注册用户)
    private MessageEvent onGroupMemberInviteAgreeAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_INVITE_AGREE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "发送失败");
            }
        }
        return event;
    }

    // 拒绝邀请(游客)
    private MessageEvent onGroupMemberInviteRefuseAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_INVITE_REFUSE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "发送失败");
            }
        }
        return event;
    }

    // 拒绝邀请(注册用户)
    private MessageEvent onGroupMemberInviteRefuseAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_INVITE_REFUSE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "发送失败");
            }
        }
        return event;
    }

    // 申请入群(游客)
    private MessageEvent onGroupMemberApplyAsTouristsReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_APPLY_TOURISTS);
        event.setResponse(code, msg);
        return event;
    }

    // 申请入群(注册用户)
    private MessageEvent onGroupMemberApplyAsRegisteredReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_APPLY_REGISTERED);
        event.setResponse(code, msg);
        return event;
    }

    // 同意申请(游客)
    private MessageEvent onGroupMemberApplyAgreeAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_APPLY_AGREE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "发送失败");
            }
        }
        return event;
    }

    // 同意申请(注册用户)
    private MessageEvent onGroupMemberApplyAgreeAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_APPLY_AGREE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "发送失败");
            }
        }
        return event;
    }

    // 拒绝申请(游客)
    private MessageEvent onGroupMemberApplyRefuseAsTouristsReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_APPLY_REFUSE_TOURISTS);
        event.setResponse(code, msg);
        return event;
    }

    // 拒绝申请(注册用户)
    private MessageEvent onGroupMemberApplyRefuseAsRegisteredReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_APPLY_REFUSE_REGISTERED);
        event.setResponse(code, msg);
        return event;
    }

    // 删除群成员
    private MessageEvent onGroupMemberDeleteReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_DELETE);
        event.setResponse(code, msg);
        return event;
    }

    private MessageEvent onGroupMemberExitReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_EXIT);
        event.setResponse(code, msg);
        return event;
    }

    // 删除群成员(游客)
    private MessageEvent onGroupMemberDeleteAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_DELETE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "删除异常");
            }
        }
        return event;
    }

    // 删除群成员(注册用户)
    private MessageEvent onGroupMemberDeleteAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_DELETE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "删除异常");
            }
        }
        return event;
    }

    // 修改群公告(游客)
    private MessageEvent onGroupAnnouncementUpdateAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_ANNOUNCEMENT_UPDATE_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "修改失败");
            }
        }
        return event;
    }

    // 修改群公告(注册用户)
    private MessageEvent onGroupAnnouncementUpdateAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_ANNOUNCEMENT_UPDATE_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "修改失败");
            }
        }
        return event;
    }

    // 更新群公告(游客)
    private MessageEvent onGroupAnnouncementSelectAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_ANNOUNCEMENT_SELECT_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "更新失败");
            }
        }
        return event;
    }

    // 更新群公告(注册用户)
    private MessageEvent onGroupAnnouncementSelectAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_ANNOUNCEMENT_SELECT_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "更新失败");
            }
        }
        return event;
    }

    // 设置昵称(游客)
    private MessageEvent onPersonalNicknameAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsUser touristsUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_NICKNAME_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != touristsUser) {
                TouristsUserDto touristsUserDto = new TouristsUserDto(touristsUser);
                event.setData(touristsUserDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置昵称(注册用户)
    private MessageEvent onPersonalNicknameAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredUser registeredUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_NICKNAME_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != registeredUser) {
                RegisteredUserDto registeredUserDto = new RegisteredUserDto(registeredUser);
                event.setData(registeredUserDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置头像(游客)
    private MessageEvent onPersonalAvatarAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsUser touristsUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_AVATAR_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != touristsUser) {
                TouristsUserDto touristsUserDto = new TouristsUserDto(touristsUser);
                event.setData(touristsUserDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置头像(注册用户)
    private MessageEvent onPersonalAvatarAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredUser registeredUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_AVATAR_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != registeredUser) {
                RegisteredUserDto registeredUserDto = new RegisteredUserDto(registeredUser);
                event.setData(registeredUserDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 获取验证码
    private MessageEvent onPersonalVerificationCodeReader(int code, String msg, BusinessProtocolEntities.RegisteredUser registeredUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.VERIFICATION_CODE);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != registeredUser) {
                RegisteredUserDto registeredUserDto = new RegisteredUserDto(registeredUser);
                event.setData(registeredUserDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 重置密码-验证
    private MessageEvent onPersonalResetSecretVerifyReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.RESET_SECRET_VERIFY);
        event.setResponse(code, msg);
        return event;
    }

    // 重置密码-重置
    private MessageEvent onPersonalResetSecretReader(int code, String msg) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.RESET_SECRET);
        event.setResponse(code, msg);
        return event;
    }

    // 设置手机
    private MessageEvent onPersonalSetupPhoneReader(int code, String msg, BusinessProtocolEntities.RegisteredUser registeredUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.SETUP_PHONE);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != registeredUser) {
                RegisteredUserDto registeredUserDto = new RegisteredUserDto(registeredUser);
                event.setData(registeredUserDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 修改手机
    private MessageEvent onPersonalEditPhoneReader(int code, String msg, BusinessProtocolEntities.RegisteredUser registeredUser) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.SETUP_PHONE_EDIT);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != registeredUser) {
                RegisteredUserDto registeredUserDto = new RegisteredUserDto(registeredUser);
                event.setData(registeredUserDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-是否接收离线消息(游客)
    private MessageEvent onPersonalOfflineMsgAsTouristsReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_OFFLINE_MSG_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-是否接收离线消息(注册用户)
    private MessageEvent onPersonalOfflineMsgAsRegisteredReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_OFFLINE_MSG_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-好友阅后即焚(游客)
    private MessageEvent onPersonalFriendSnapchatAsTouristsReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_FRIEND_SNAPCHAT_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-好友阅后即焚(注册用户)
    private MessageEvent onPersonalFriendSnapchatAsRegisteredReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_FRIEND_SNAPCHAT_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-好友阅后即焚时长(游客)
    private MessageEvent onPersonalFriendSnapchatLengthAsTouristsReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_FRIEND_SNAPCHAT_LENGTH_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-好友阅后即焚时长(注册用户)
    private MessageEvent onPersonalFriendSnapchatLengthAsRegisteredReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_FRIEND_SNAPCHAT_LENGTH_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-群阅后即焚开关(游客)
    private MessageEvent onPersonalGroupSnapchatAsTouristsReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_GROUP_SNAPCHAT_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-群阅后即焚开关(注册用户)
    private MessageEvent onPersonalGroupSnapchatAsRegisteredReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_GROUP_SNAPCHAT_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-群阅后即焚时长(游客)
    private MessageEvent onPersonalGroupSnapchatLengthAsTouristsReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_GROUP_SNAPCHAT_LENGTH_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-群阅后即焚时长(注册用户)
    private MessageEvent onPersonalGroupSnapchatLengthAsRegisteredReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_GROUP_SNAPCHAT_LENGTH_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-是否每次退出清理(游客)
    private MessageEvent onPersonalExitCleanAsTouristsReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_EXIT_CLEAN_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-是否每次退出清理(注册用户)
    private MessageEvent onPersonalExitCleanAsRegisteredReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_EXIT_CLEAN_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-定期清理周期(游客)
    private MessageEvent onPersonalTimerCleanAsTouristsReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_TIMER_CLEAN_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置-定期清理周期(注册用户)
    private MessageEvent onPersonalTimerCleanAsRegisteredReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_TIMER_CLEAN_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != settings) {
                SettingsDto settingsDto = new SettingsDto(settings);
                event.setData(settingsDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置好友备注(游客)
    private MessageEvent onFriendAliasAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_ALIAS_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置好友备注(注册用户)
    private MessageEvent onFriendAliasAsRegisteredsReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_ALIAS_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 好友设置阅后即焚(游客)
    private MessageEvent onFriendSnapchatAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_SNAPCHAT_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 好友设置阅后即焚(注册用户)
    private MessageEvent onFriendSnapchatAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_SNAPCHAT_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 好友设置阅后即焚时长(游客)
    private MessageEvent onFriendSnapchatLengthAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_SNAPCHAT_LENGTH_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 好友设置阅后即焚时长(注册用户)
    private MessageEvent onFriendSnapchatLengthAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_SNAPCHAT_LENGTH_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 好友设置是否离线消息接收(游客)
    private MessageEvent onFriendOfflineMsgAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_OFFLINE_MSG_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 好友设置是否离线消息接收(注册用户)
    private MessageEvent onFriendOfflineMsgAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredFriend friend) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_OFFLINE_MSG_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != friend) {
                FriendDto friendDto = new FriendDto(friend);
                event.setData(friendDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置群名称(游客)
    private MessageEvent onGroupNameAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_NAME_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            }
        }
        return event;
    }

    // 设置群名称(注册用户)
    private MessageEvent onGroupNameAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_NAME_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            }
        }
        return event;
    }

    // 设置阅后即焚开关(游客)
    private MessageEvent onGroupSnapchatAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_SNAPCHAT_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置阅后即焚开关(注册用户)
    private MessageEvent onGroupSnapchatAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_SNAPCHAT_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置阅后即焚时长(游客)
    private MessageEvent onGroupSnapchatLengthAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_SNAPCHAT_LENGTH_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置阅后即焚时长(注册用户)
    private MessageEvent onGroupSnapchatLengthAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroup group) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_SNAPCHAT_LENGTH_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != group) {
                GroupDto groupDto = new GroupDto(group);
                event.setData(groupDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置群成员群昵称(游客)
    private MessageEvent onGroupMemberNickAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_NICK_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置群成员群昵称(注册用户)
    private MessageEvent onGroupMemberNickAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroupMember groupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_NICK_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != groupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
                event.setData(groupMemberDto.toJson());
            } else {
                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
            }
        }
        return event;
    }

    // 设置群成员备注
    private MessageEvent onGroupMemberAliasReader(int code, String msg, BusinessProtocolEntities.TouristsGroupMember tGroupMember, BusinessProtocolEntities.RegisteredGroupMember rGroupMember) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_ALIAS_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != tGroupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(tGroupMember);
                event.setData(groupMemberDto.toJson());
                event.setAction(EventConstants.Action.GROUP_MEMBER_ALIAS_TOURISTS);
            }
            if (null != rGroupMember) {
                GroupMemberDto groupMemberDto = new GroupMemberDto(rGroupMember);
                event.setData(groupMemberDto.toJson());
                event.setAction(EventConstants.Action.GROUP_MEMBER_ALIAS_REGISTERED);
            }
        }
        return event;
    }

    // 设置群成员备注(游客)
//    private MessageEvent onGroupMemberAliasAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsGroupMember groupMember) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_ALIAS_TOURISTS);
//        event.setResponse(code, msg);
//        if (code == IMSContacts.ResponseCode.SUCCESS) {
//            if (null != groupMember) {
//                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
//                event.setData(groupMemberDto.toJson());
//            } else {
//                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
//            }
//        }
//        return event;
//    }

    // 设置群成员备注(注册用户)
//    private MessageEvent onGroupMemberAliasAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredGroupMember groupMember) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_MEMBER_ALIAS_REGISTERED);
//        event.setResponse(code, msg);
//        if (code == IMSContacts.ResponseCode.SUCCESS) {
//            if (null != groupMember) {
//                GroupMemberDto groupMemberDto = new GroupMemberDto(groupMember);
//                event.setData(groupMemberDto.toJson());
//            } else {
//                event.setResponse(IMSContacts.ResponseCode.FAILURE, "设置失败");
//            }
//        }
//        return event;
//    }

    // 系统通知列表
    private MessageEvent onNotificationsReader(int code, String msg, List<BusinessProtocolEntities.SysNotify> sysNotifyList) {
        MessageEvent event = MessageEvent.createReaderEvent(UserPreferences.isRegistered() ? EventConstants.Action.NOTIFICATIONS_REGISTERED : EventConstants.Action.NOTIFICATIONS_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (CollectionUtils.isEmpty(sysNotifyList)) {
                event.setCode(IMSContacts.ResponseCode.EMPTY_RESULT);
            } else {
                List<SysNotifyDto> sysNotifyDtoList = new ArrayList<>();
                for (BusinessProtocolEntities.SysNotify sysNotify : sysNotifyList) {
                    BusinessProtocolEntities.Picture picture = sysNotify.getPicture();
                    String thumbPath = null;
                    if (picture != null) {
                        File folder = AlbumUtils.getAlbumRootThumbFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
                        FileOperator.mkDirectory(folder);
                        thumbPath = FileOperator.saveFile(folder.getAbsolutePath(), picture.getThumbnail().asReadOnlyByteBuffer());
                    }
                    sysNotifyDtoList.add(new SysNotifyDto(sysNotify, thumbPath));
                }
                event.setData(JsonUtils.convertListToJson(sysNotifyDtoList));
            }
        }
        return event;
    }

    // 通知列表(游客)
    private MessageEvent onNotificationsAsTouristsReader(int code, String msg, List<BusinessProtocolEntities.SysNotify> sysNotifyList, List<BusinessProtocolEntities.TouristsNotify> notifyList) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.NOTIFICATIONS_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (CollectionUtils.isEmpty(sysNotifyList) && CollectionUtils.isEmpty(notifyList)) {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "暂无通知");
            } else {
                List<SysNotifyDto> sysNotifyDtoList = null;
                if (!CollectionUtils.isEmpty(sysNotifyList)) {
                    sysNotifyDtoList = new ArrayList<>();
                    for (BusinessProtocolEntities.SysNotify sysNotify : sysNotifyList) {
                        BusinessProtocolEntities.Picture picture = sysNotify.getPicture();
                        String thumbPath = null;
                        if (picture != null) {
                            File folder = AlbumUtils.getAlbumRootThumbFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
                            FileOperator.mkDirectory(folder);
                            thumbPath = FileOperator.saveFile(folder.getAbsolutePath(), picture.getThumbnail().asReadOnlyByteBuffer());
                        }
                        sysNotifyDtoList.add(new SysNotifyDto(sysNotify, thumbPath));
                    }
                }
                List<NotifyDto> notifyDtoList = null;
                if (!CollectionUtils.isEmpty(notifyList)) {
                    notifyDtoList = new ArrayList<>();
                    for (BusinessProtocolEntities.TouristsNotify touristsNotify : notifyList)
                        notifyDtoList.add(new NotifyDto(touristsNotify));
                }
                NotifyListDto notifyListDto = new NotifyListDto(sysNotifyDtoList, notifyDtoList);
                event.setData(notifyListDto.toJson());
            }
        }
        return event;
    }

    // 通知列表(注册用户)
    private MessageEvent onNotificationsAsRegisteredReader(int code, String msg, List<BusinessProtocolEntities.SysNotify> sysNotifyList, List<BusinessProtocolEntities.RegisteredNotify> notifyList) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.NOTIFICATIONS_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (CollectionUtils.isEmpty(sysNotifyList) && CollectionUtils.isEmpty(notifyList)) {
                event.setResponse(IMSContacts.ResponseCode.EMPTY_RESULT, "暂无通知");
            } else {
                List<SysNotifyDto> sysNotifyDtoList = null;
                if (!CollectionUtils.isEmpty(sysNotifyList)) {
                    sysNotifyDtoList = new ArrayList<>();
                    for (BusinessProtocolEntities.SysNotify sysNotify : sysNotifyList) {
                        BusinessProtocolEntities.Picture picture = sysNotify.getPicture();
                        String thumbPath = null;
                        if (picture != null) {
                            File folder = AlbumUtils.getAlbumRootThumbFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
                            FileOperator.mkDirectory(folder);
                            thumbPath = FileOperator.saveFile(folder.getAbsolutePath(), picture.getThumbnail().asReadOnlyByteBuffer());
                        }
                        sysNotifyDtoList.add(new SysNotifyDto(sysNotify, thumbPath));
                    }
                }
                List<NotifyDto> notifyDtoList = null;
                if (!CollectionUtils.isEmpty(notifyList)) {
                    notifyDtoList = new ArrayList<>();
                    for (BusinessProtocolEntities.RegisteredNotify registeredNotify : notifyList)
                        notifyDtoList.add(new NotifyDto(registeredNotify));
                }
                NotifyListDto notifyListDto = new NotifyListDto(sysNotifyDtoList, notifyDtoList);
                event.setData(notifyListDto.toJson());
            }
        }
        return event;
    }

    // 系统通知
    private MessageEvent onSysNotificationsReader(int code, String msg, BusinessProtocolEntities.SysNotify sysNotify) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.SYS_NOTIFICATIONS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != sysNotify) {
                BusinessProtocolEntities.Picture picture = sysNotify.getPicture();
                String thumbPath = null;
                if (picture != null) {
                    File folder = AlbumUtils.getAlbumRootThumbFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
                    FileOperator.mkDirectory(folder);
                    thumbPath = FileOperator.saveFile(folder.getAbsolutePath(), picture.getThumbnail().asReadOnlyByteBuffer());
                }
                SysNotifyDto sysNotifyDto = new SysNotifyDto(sysNotify, thumbPath);
                event.setData(sysNotifyDto.toJson());
            }
        }
        return event;
    }

    // 用户消息通知(游客)
    private MessageEvent onUserNotificationsAsTouristsReader(int code, String msg, BusinessProtocolEntities.TouristsNotify notify) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.USER_NOTIFICATIONS_TOURISTS);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != notify) {
                NotifyDto notifyDto = new NotifyDto(notify);
                event.setData(notifyDto.toJson());
            }
        }
        return event;
    }

    // 用户消息通知(注册用户)
    private MessageEvent onUserNotificationsAsRegisteredReader(int code, String msg, BusinessProtocolEntities.RegisteredNotify notify) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.USER_NOTIFICATIONS_REGISTERED);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            if (null != notify) {
                NotifyDto notifyDto = new NotifyDto(notify);
                event.setData(notifyDto.toJson());
            }
        }
        return event;
    }

    // 单人(1v1)聊天
    private MessageEvent onFriendChatMessageReader(int code, String msg, BusinessProtocolMessageStandard.Head head) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_CHAT_TOURISTS);
        event.setResponse(code, msg);
        if (null != head) {
            String msgId = head.getUniqueIdentify();
            event.setData(msgId);
            try {
                ChatTableBean table = ChatTableBean.queryByMessageId(msgId);
                if (table != null) {
                    table.setSendState(code == IMSContacts.ResponseCode.SUCCESS ? ChatTableBean.SEND_SUCCESS : ChatTableBean.SEND_FAIL);
                    DbController.getInstance().getWrite().getChatTableBeanDao().update(table);
                }
            } catch (Exception e) {
                Logger.print(e.getMessage());
            }
        }
        return event;
    }

//    @Deprecated
//    private MessageEvent onFriendChatMessageReader(int code, String msg, BusinessProtocolMessageStandard.UnifiedEntranceMessage unifiedEntranceMessage) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.FRIEND_CHAT_TOURISTS);
//        event.setResponse(code, msg);
//        BusinessProtocolMessageStandard.Head head = unifiedEntranceMessage.getHead();
//        if (null == head) return null;
//        if (UserPreferences.getUserId().equals(head.getFromId())) {
//            event.setAction(EventConstants.Action.CHAT_SEND_CALLBACK);
//            event.setData(head.getUniqueIdentify());
//            return event;
//        }
//        BusinessProtocolMessages.FriendChatProtocol friendChatProtocol = unifiedEntranceMessage.getFriendChatProtocol();
//        if (null == friendChatProtocol) return null;
//        FriendDto friendDto;
//        if (IMSContacts.MsgType.FRIEND_CHAT_TOURISTS.equals(head.getMsgType())) {
//            BusinessProtocolEntities.TouristsFriend touristsFriend = friendChatProtocol.getTouristsFriend();
//            friendDto = new FriendDto(touristsFriend);
//        } else {
//            BusinessProtocolEntities.RegisteredFriend registeredFriend = friendChatProtocol.getRegisteredFriend();
//            friendDto = new FriendDto(registeredFriend);
//        }
//        BusinessProtocolEntities.ChatMessage chatMessage = friendChatProtocol.getChatMessage();
//        String path = null;
//        if (chatMessage.getChatType() == IMSContacts.MsgContentType.PICTURE) {
//            BusinessProtocolEntities.Picture picture = chatMessage.getPicture();
//            if (null != picture) {
//                File folder = AlbumUtils.getAlbumRootThumbFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
//                FileOperator.mkDirectory(folder);
//                path = FileOperator.saveFile(folder.getAbsolutePath(), picture.getThumbnail().asReadOnlyByteBuffer());
//            }
//        } else if (chatMessage.getChatType() == IMSContacts.MsgContentType.VIDEO) {
//            BusinessProtocolEntities.Video video = chatMessage.getVideo();
//            if (null != video) {
//                File folder = AlbumUtils.getAlbumRootThumbFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
//                FileOperator.mkDirectory(folder);
//                path = FileOperator.saveFile(folder.getAbsolutePath(), video.getThumbnail().asReadOnlyByteBuffer());
//            }
//        } else if (chatMessage.getChatType() == IMSContacts.MsgContentType.VOICE) {
//            BusinessProtocolEntities.Voice voice = chatMessage.getVoice();
//            if (null != voice) {
//                File folder = AlbumUtils.getAlbumRecordFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
//                FileOperator.mkDirectory(folder);
//                path = FileOperator.saveFile(folder.getAbsolutePath(), voice.getContent().asReadOnlyByteBuffer());
//            }
//        }
//        ChatMessageDto chatMessageDto = new ChatMessageDto(chatMessage, path);
//        ChatFriendMsgDto chatFriendMsgDto = new ChatFriendMsgDto(friendDto, chatMessageDto);
//        event.setData(chatFriendMsgDto.toJson());
//        return event;
//    }

    // 多人(群)聊天
    private MessageEvent onGroupChatMessageReader(int code, String msg, BusinessProtocolMessageStandard.Head head) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_CHAT_TOURISTS);
        event.setResponse(code, msg);
        if (null != head) {
            String msgId = head.getUniqueIdentify();
            event.setData(msgId);
            try {
                ChatTableBean table = ChatTableBean.queryByMessageId(msgId);
                if (table != null) {
                    table.setSendState(code == IMSContacts.ResponseCode.SUCCESS ? ChatTableBean.SEND_SUCCESS : ChatTableBean.SEND_FAIL);
                    DbController.getInstance().getWrite().getChatTableBeanDao().update(table);
                }
            } catch (Exception e) {
                Logger.print(e.getMessage());
            }
        }
        return event;
    }

//    @Deprecated
//    private MessageEvent onGroupChatMessageReader(int code, String msg, BusinessProtocolMessageStandard.UnifiedEntranceMessage unifiedEntranceMessage) {
//        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_CHAT_TOURISTS);
//        event.setResponse(code, msg);
//        BusinessProtocolMessageStandard.Head head = unifiedEntranceMessage.getHead();
//        if (null == head) return null;
//        if (UserPreferences.getUserId().equals(head.getFromId())) {
//            event.setAction(EventConstants.Action.CHAT_SEND_CALLBACK);
//            event.setData(head.getUniqueIdentify());
//            return event;
//        }
//        BusinessProtocolMessages.GroupChatProtocol groupChatProtocol = unifiedEntranceMessage.getGroupChatProtocol();
//        if (null == groupChatProtocol) return null;
//        GroupMemberDto groupMemberDto;
//        if (IMSContacts.MsgType.FRIEND_CHAT_TOURISTS.equals(head.getMsgType())) {
//            BusinessProtocolEntities.TouristsGroupMember touristsGroupMember = groupChatProtocol.getTouristsGroupMember();
//            groupMemberDto = new GroupMemberDto(touristsGroupMember);
//        } else {
//            BusinessProtocolEntities.RegisteredGroupMember registeredGroupMember = groupChatProtocol.getRegisteredGroupMember();
//            groupMemberDto = new GroupMemberDto(registeredGroupMember);
//        }
//        BusinessProtocolEntities.ChatMessage chatMessage = groupChatProtocol.getChatMessage();
//        String path = null;
//        if (chatMessage.getChatType() == IMSContacts.MsgContentType.PICTURE) {
//            BusinessProtocolEntities.Picture picture = chatMessage.getPicture();
//            if (null != picture) {
//                File folder = AlbumUtils.getAlbumRootThumbFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
//                FileOperator.mkDirectory(folder);
//                path = FileOperator.saveFile(folder.getAbsolutePath(), picture.getThumbnail().asReadOnlyByteBuffer());
//            }
//        } else if (chatMessage.getChatType() == IMSContacts.MsgContentType.VIDEO) {
//            BusinessProtocolEntities.Video video = chatMessage.getVideo();
//            if (null != video) {
//                File folder = AlbumUtils.getAlbumRootThumbFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
//                FileOperator.mkDirectory(folder);
//                path = FileOperator.saveFile(folder.getAbsolutePath(), video.getThumbnail().asReadOnlyByteBuffer());
//            }
//        } else if (chatMessage.getChatType() == IMSContacts.MsgContentType.VOICE) {
//            BusinessProtocolEntities.Voice voice = chatMessage.getVoice();
//            if (null != voice) {
//                File folder = AlbumUtils.getAlbumRecordFile(App.getContext(), AlbumUtils.PACK_NAME, UserPreferences.getUserId());
//                FileOperator.mkDirectory(folder);
//                path = FileOperator.saveFile(folder.getAbsolutePath(), voice.getContent().asReadOnlyByteBuffer());
//            }
//        }
//        ChatMessageDto chatMessageDto = new ChatMessageDto(chatMessage, path);
//        ChatGroupMsgDto chatGroupMsgDto = new ChatGroupMsgDto(groupMemberDto, chatMessageDto);
//        event.setData(chatGroupMsgDto.toJson());
//        return event;
//    }

    // 离线消息(游客)
    private MessageEvent onOffFriendMessageAsTouristsReader(int code, String msg, BusinessProtocolMessages.OffFriendMessageListProtocol protocol) {
        IMSOfflineMessageHandler.handleOfflineProtocol(protocol);

        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.OFF_MESSAGE_SEND_TOURIST);
        event.setResponse(code, msg);
        event.setData(protocol.getPage() + "," + protocol.getRequest());
        return event;
    }

    // 离线消息(注册用户)
    private MessageEvent onOffFriendMessageAsRegisteredReader(int code, String msg, BusinessProtocolMessages.OffFriendMessageListProtocol protocol) {
        IMSOfflineMessageHandler.handleOfflineProtocol(protocol);

        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.OFF_MESSAGE_SEND_REGIST);
        event.setResponse(code, msg);
        event.setData(protocol.getPage() + "," + protocol.getRequest());
        return event;
    }

    // 离线消息(群组)
    private MessageEvent onGroupOfflineMessageReader(int code, String msg, BusinessProtocolMessages.OfflineGroupMessageProtocol protocol) {
        IMSOfflineMessageHandler.handleGroupOfflineMessage(protocol.getGroupOfflineMessageList());

        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.GROUP_CHART_OFF_LINE_MSG);
        event.setResponse(code, msg);
        event.setData(protocol.getPage() + "," + protocol.getRequest());
        return event;
    }

    // 检查更新
    private MessageEvent onCheckForUpdatesReader(int code, String msg, BusinessProtocolMessages.CheckForUpdatesProtocol version) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.CHECK_FOR_UPDATES);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            VersionDto versionDto = new VersionDto(version);
            event.setData(versionDto.toJson());
        }
        return event;
    }

    private MessageEvent onPersonalSettingsInfoReader(int code, String msg, BusinessProtocolEntities.Settings settings) {
        MessageEvent event = MessageEvent.createReaderEvent(EventConstants.Action.PERSONAL_SETTINGS_INFO);
        event.setResponse(code, msg);
        if (code == IMSContacts.ResponseCode.SUCCESS) {
            SettingsDto settingDto = new SettingsDto(settings);
            event.setData(settingDto.toJson());
        }
        return event;
    }
}